.SUFFIXES: .asm
# Makefile for JamesM's kernel tutorials.
# The C and C++ rules are already setup by default.
# The only one that needs changing is the assembler 
# rule, as we use nasm instead of GNU as.

SOURCES=include/boot.o lib/libc.a include/monitor.o include/common.o include/descriptor_tables.o include/isr.o include/interrupt.o include/gdt.o include/timer.o include/kheap.o include/paging.o include/ordered_array.o include/fs.o include/initrd.o include/task.o include/process.o include/syscall.o main.o

SRC2=cst/keybrdz.o osd/kprintf.o osd/kstart.o osd/kbd.o osd/video.o osd/tasks.o osd/sched.o lib/libc.a osd/main2.o

CFLAGS=-nostdlib -nostdinc -fno-builtin -I./include -I./osd -I./inc -I./lib -I./cst
CXXFLAGS=-I./include -I./osd -I./inc -I./lib -I./cst
LDFLAGS=-Tlink.ld
LD2=-Tkrnl1m.ld
ASFLAGS=-felf

all: $(SOURCES) $(SRC2) cst/keybrd.o link

clean:
	-rm *.o kernel include/*.o osd/*.o cst/*.o

link:
	ld $(LDFLAGS) -o kernel -b elf32-i386 $(SOURCES) $(SRC2) -b binary cst/keybrd.o --oformat=elf32-i386

.s.o:
	nasm $(ASFLAGS) $<

.asm.o:
	nasm -f elf -i./inc -o$@ $<

cst/keybrd.o: ./cst/keybrd.b
	nasm -f bin -o cst/keybrd.o cst/keybrd.b

kstart.o: osd/kstart.asm

lib/libc.a: ./lib/linux.mak
	make -C ./lib -f linux.mak

